﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using WebChatApi.Common.Interface;

namespace WebChatApi.Common
{
    /// <summary>
    /// A model class for saving user authority information
    /// </summary>
    [DataContract]
    
    public class AuthorityInfo : IIdentifiable
    {
        #region Properties

        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>
        /// The key.
        /// </value>
        [DataMember]
        public Guid Key
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the token.
        /// </summary>
        /// <value>
        /// The token.
        /// </value>
        [DataMember]
        public string Token
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the user key.
        /// </summary>
        /// <value>
        /// The user key.
        /// </value>
        [DataMember]
        public Guid UserKey
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the type of the source.
        /// For client request, value should be combined with Platform and App.
        /// For example:
        /// When Loggers app in iOS send a request, value should be 0x0011 (0x0001 + 0x0010). 
        /// </summary>
        /// <value>
        /// The type of the source.
        /// </value>
        [DataMember]
        public ApplicationSource SourceType
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the device identity.
        /// </summary>
        /// <value>
        /// The device identity.
        /// </value>
        [DataMember]
        public string DeviceIdentity
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the created stamp.
        /// </summary>
        /// <value>
        /// The created stamp.
        /// </value>
        [DataMember]
        public DateTime CreatedStamp
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the last updated stamp.
        /// </summary>
        /// <value>
        /// The last updated stamp.
        /// </value>
        [DataMember]
        public DateTime LastUpdatedStamp
        {
            get;
            set;
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="AuthorityInfo"/> class.
        /// </summary>
        public AuthorityInfo()
            : this(new Guid())
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AuthorityInfo"/> class.
        /// </summary>
        /// <param name="userKey">The user key.</param>
        public AuthorityInfo(Guid userKey)
            : this(Guid.NewGuid(), userKey)
        {
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="AuthorityInfo"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="userKey">The user key.</param>
        public AuthorityInfo(Guid key, Guid userKey)
        {
            this.Key = key;
            this.UserKey = userKey;
            this.LastUpdatedStamp = this.CreatedStamp = DateTime.UtcNow;
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="AuthorityInfo"/> class.
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="token">The token.</param>
        /// <param name="sourceType">Type of the source.</param>
        public AuthorityInfo(Guid userKey, string token, ApplicationSource sourceType)
        {
            this.Key = Guid.NewGuid();
            this.UserKey = userKey;
            this.Token = token;
            this.SourceType = sourceType;
            this.LastUpdatedStamp = this.CreatedStamp = DateTime.UtcNow;
        }

        #endregion
    }
}
